<template>
	<view class="content">
		<view class="logoBox">
			<image :src="imgUrl+'/static/wap/img/dian@2x.png'" mode="" class="logo"></image>
		</view>
		<view class="name">能源运维</view>
		<view class="main">
			<view class="mainLine">
				<view class="mainLineName">账号:</view>
				<input type="text" value="" placeholder="请输入账号" placeholder-style="color:#000000" v-model="username" />
			</view>
			<view class="mainLine">
				<view class="mainLineName">密码:</view>
				<input type="password" value="" placeholder="请输入密码" placeholder-style="color:#000000" v-model="password" />
			</view>
			<view class="loginTis">首次登陆账号为您的手机号，密码是身份证后六位</view>
		</view>
		<!-- #ifdef H5 -->
		<view class="loginBtn" @click="login"> 登录</view>
		<!-- #endif -->
		<!-- #ifdef MP-WEIXIN -->
		<view class="loginBtn" @click="login2"> 登录</view>
		<!-- #endif -->
		<view class="loginBtn login_special" @click="forgetPass">忘记密码</view>
	</view>

</template>

<script>
	import util from '../../static/util.js'
	export default {
		data() {
			return {
				imgUrl: util.globalData.imgPre,
				title: 'Hello',
				username: '',
				password: '',
				type: 1,
				wechat_id: '',
			}
		},
		onLoad(opt) {
			this.type = opt.type;
			this.wechat_id = opt.wechat_id;
		},
		methods: {
			forgetPass() {
				uni.navigateTo({
					url: "../forgetPass/forgetPass"
				})
			},
			login() {
				var that = this;
				that.ajax({
					url: 'api/user/login',
					data: {
						username: that.username,
						password: that.password,
						wechat_id: that.wechat_id,
						type: 2,
					},
					success: function(res) {
						if (res.code == 200) {
							uni.setStorage({
								key: 'token',
								data: res.data.token
							}) 
							
							//#ifdef H5
							window.location.href = "https://nengyuan.chuangxiangdianli.com/h5/#/"
							//#endif
							
							//#ifdef MP-WEIXIN
							uni.switchTab({
								url: '../index/index'
							})
							//#endif
							
						} else {
							uni.showToast({
								title: "" + res.msg,
								icon: 'none'
							});
						}

					}
				})
			},
			login2() {
				var that = this;
				that.ajax({
					url: 'api/user/login',
					data: {
						username: that.username,
						password: that.password,
						wechat_id: that.wechat_id,
						type: 1,
					},
					success: function(res) {
						if (res.code == 200) {
							uni.setStorage({
								key: 'token',
								data: res.data.token,
								success: () => {
									that.ajax({
										url: 'api/user/getUserInfo',
										success: function(res) {
											uni.setStorage({
												key: 'userInfo',
												data: res.data,
												success() {
													uni.switchTab({
														url: '../index/index'
													})
												}
											})
										}
									})
								}
							})
							//console.log("登录成功")
						} else {
							setTimeout(function() {
								uni.showToast({
									title: "" + res.msg,
									icon: 'none',
									duration: 1500
								});
							}, 10)

						}

					},
					complete() {
						
					}
				})
			}

		},
		mounted() {
			// this.id = this.$route.query.id
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		height: 100vh;
		width: 100vw;
		background: url(https://nengyuan.chuangxiangdianli.com/static/wap/img/login_bg@2x.png) no-repeat;
		background-size: 100% 100%;
	}

	.logo {
		width: 200rpx;
		height: 200rpx;
	}

	.logoBox {
		text-align: center;
		padding-top: 200rpx;
	}

	.name {
		font-size: 48rpx;
		font-family: FZDaHei-B02S Regular, FZDaHei-B02S Regular-Regular;
		font-weight: bold;
		text-align: center;
		color: #2AABAD;
		padding-top: 56rpx;
	}


	.loginBtn {
		width: 570rpx;
		height: 90rpx;
		line-height: 90rpx;
		text-align: center;
		font-size: 36rpx;
		color: #FFFFFF;
		background: #209698;
		border-radius: 45rpx;
		margin: 0 auto;
	}

	.login_special {
		background: white;
		border: 1rpx solid #209698;
		color: #209698;
		margin-top: 20rpx;
	}

	.main {
		padding: 90rpx;
		padding-top: 140rpx;
	}

	.mainLine {
		display: flex;
		padding-bottom: 100rpx;
		// font-size: 25rpx;
	}

	.mainLineName {
		font-size: 30rpx;
		color: #209698;
		width: 100rpx;
	}

	.mainLine input {
		border-bottom: 1px solid #000000;
		width: 470rpx;
		color: #333333;
		font-size: 30rpx;
		padding-bottom: 20rpx;
	}

	.loginTis {
		color: #333333;
		text-align: center;
		font-size: 26rpx;
	}
</style>
